<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
         /*
            统计数组中元素出现的次数
            [1,2,3,1,1,1,2,2,3,3,4]
                1出现的次数 4
                2出现的次数 3
                3出现的次数 3
                4出现的次数 1
         */
        var arr = [1,2,3,1,1,1,2,2,3,3,4];
        var res = arr.reduce(function(pic,cur){
            if(cur in pic){
                pic[cur] += 1;
            }else{
                pic[cur] = 1;
            }
            return pic
        },{})
        for (var key in res) {
            console.log(key + '出现的次数' + res[key]);
        }
    </script>
</body>
</html>